package n_swing_jtable;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Color;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class JTableMain extends JFrame {

	JTableEx1 jtex1;
	JTableEx2 jtex2;
	JTableEx3 jtex3;
	
	private JDesktopPane contentPane;
	private JMenuBar menuBar;
	private JMenu mnNewMenu;
	private JMenuItem mntmNewMenuItem;
	private JMenu mnNewMenu_1;
	private JMenuItem mntmTyp;
	private JMenuItem mntmAbstractModelType;
	private JMenuItem mntmDefaulttablemodel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JTableMain frame = new JTableMain();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public JTableMain() {
		setTitle("JTable Samples");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 624, 429);
		setJMenuBar(getMenuBar_1());
		contentPane = new JDesktopPane();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
	}

	private JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.add(getMnNewMenu());
			menuBar.add(getMnNewMenu_1());
		}
		return menuBar;
	}
	private JMenu getMnNewMenu() {
		if (mnNewMenu == null) {
			mnNewMenu = new JMenu("기본형");
			mnNewMenu.add(getMntmNewMenuItem());
			mnNewMenu.add(getMntmTyp());
		}
		return mnNewMenu;
	}
	private JMenuItem getMntmNewMenuItem() {
		if (mntmNewMenuItem == null) {
			mntmNewMenuItem = new JMenuItem("type 1");
			mntmNewMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					if(jtex1 == null){
						jtex1 = new JTableEx1();
						contentPane.add(jtex1);
					}
					jtex1.setVisible(true);
					
				}
			});
		}
		return mntmNewMenuItem;
	}
	private JMenu getMnNewMenu_1() {
		if (mnNewMenu_1 == null) {
			mnNewMenu_1 = new JMenu("모델형");
			mnNewMenu_1.add(getMntmDefaulttablemodel());
			mnNewMenu_1.add(getMntmAbstractModelType());
		}
		return mnNewMenu_1;
	}
	private JMenuItem getMntmTyp() {
		if (mntmTyp == null) {
			mntmTyp = new JMenuItem("type 2");
			mntmTyp.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
				}
			});
		}
		return mntmTyp;
	}
	private JMenuItem getMntmAbstractModelType() {
		if (mntmAbstractModelType == null) {
			mntmAbstractModelType = new JMenuItem("AbstractTableModel 1");
			mntmAbstractModelType.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(jtex3 == null){
						jtex3 = new JTableEx3();
						contentPane.add(jtex3);
					}
					jtex3.setVisible(true);
				}
			});
		}
		return mntmAbstractModelType;
	}
	private JMenuItem getMntmDefaulttablemodel() {
		if (mntmDefaulttablemodel == null) {
			mntmDefaulttablemodel = new JMenuItem("DefaultTableModel 1");
			mntmDefaulttablemodel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(jtex2 == null){
						jtex2 = new JTableEx2();
						contentPane.add(jtex2);
					}
					jtex2.setVisible(true);
				}
			});
		}
		return mntmDefaulttablemodel;
	}
}
